<?php
declare (strict_types=1);

namespace app\admin\middleware;

use addons\BuilderPlus\contract\Admin;

class Verify
{
    /**
     * @var string 登录标识key
     */
    protected $session_id = 'admin_id';

    /**
     * @var string 登录密码标识key
     */
    protected $session_token = 'password_token';

    /**
     * @var int 当前模块type
     */
    protected $type = 1;

    use Admin;

    /**
     * @var string[] 无需验证方法，* 代表全部，格式：控制器/方法名
     */
    protected $allow = [
        '*/getList',
        'index/*'
    ];

    public function handle($request, \Closure $next)
    {
        $result = $this->verify();

        return is_array($result) ? match ($result['type']) {
            1 => redirect($result['url']),
            -1 => $this->error($result['msg']),
            default => $this->error('加载失败')
        } : $next($result);
    }
}